package com.demo.serviceImpl;

import com.demo.entity.ExcelPo;
import com.demo.excel.CustomField;
import com.demo.excel.ExcelExport;
import com.demo.excel.ExcelParamModel;
import com.demo.service.ExcelService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author zqc
 * @Date 2021/04/01 11:28
 * @Description Excel操作服务层实现
 */
@Service
public class ExcelServiceImpl implements ExcelService {

    @Override
    public void exportExcelPoInfo(ExcelPo excelPo) throws Exception {
        String subTitle = "导出时间:" + System.currentTimeMillis();
        String fileName = "导出文件名";
        int[] columnWidth = {20, 20, 20, 20};
        String[] columnName = {"ID", "NAME", "学号", "成绩"};
        String[] fields = {"id", "name", "numb", "score"};
        //模拟-DB获取数据
        List<ExcelPo> newsts = new ArrayList<>();
        ExcelParamModel model = ExcelParamModel.of(fileName, columnName, columnWidth, newsts, fields,
                (value, method) -> {
                    return CustomField.acceptDate(value);
                }, "A4:L3", subTitle);
        ExcelExport.ExportWithResponse2(model);
    }

}
